<?php
class IndexController extends BaseSiteController
{
	public $layout = '//../modules/site_frontend/views/layouts/sidebar_right';
	
	public function actions()
	{
		return array(
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'minLength' => 4,
				'maxLength' => 4,
				'backColor'	=>	0x5B1509,
				'foreColor'	=>	0xFFFFFF,
				'width'		=> 70,
				'height'	=> 22,
				'offset'	=> 1,
				'padding'	=>	2,
				'testLimit'	=>	1,
				'fontFile'	=>	Yii::getPathOfAlias('ext').'/arial.ttf'
			),
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}
	public function actionIndex()
	{
		$cs = Yii::app()->getClientScript();
		$cs->registerScriptFile(Yii::app()->theme->baseUrl."/js/jquery-easing.1.2.js");
		$cs->registerScriptFile(Yii::app()->theme->baseUrl."/js/jquery-easing-compatibility.1.2.js");
		$cs->registerScriptFile(Yii::app()->theme->baseUrl."/js/coda-slider.1.1.1.js");
		$cs->registerCssFile(Yii::app()->theme->baseUrl."/css/jcarosel.css");
		$articles = FNews::model()->getArticleByCatAlias('tin-tuc','bao-tri','su-kien');
		$this->render('index',array('articles'=>$articles));
	}
	public function actionPagex()
	{
		$this->layout = '//../modules/site_frontend/views/layouts/sidebar_main';
		$alias = Yii::app()->request->getParam('alias');
		$page = Pages::getPageByAlias($alias);
		$this->render('pagex', array('page'=>$page,'alias'=>$alias));
	}
	public function actionDetail()
	{
		$this->layout = '//../modules/site_frontend/views/layouts/sidebar_main';
		$alias = Yii::app()->request->getParam('alias');
		$cat = Yii::app()->request->getParam('cat');
		$Article = FNews::getDetail($alias);
		$Others = FNews::getOtherNews($alias);
		if($Article==false)
			throw new CHttpException(301);
		$this->render('detail', array('Article'=>$Article,'cat'=>$cat,'Others'=>$Others));
	}
	public function actionCategory()
	{
		$this->layout = '//../modules/site_frontend/views/layouts/sidebar_main';
		$alias = Yii::app()->request->getParam('alias');
		if($alias=='tin-tuc'){
			$Totals = FNews::getTotalsArticleByAlias('tin-tuc','bao-tri','su-kien');
		}else{
			$Totals = FNews::getTotalsArticleByAlias($alias);
		}
		$page = new CPagination($Totals);
		$itemOnPaging = 5;
		$page->pageSize = 15;
		$curr_page = $page->getCurrentPage();
		if($alias=='tin-tuc'){
			$articles = FNews::model()->getArticleByCatAlias('tin-tuc','bao-tri','su-kien',$page->getLimit(),$page->getOffset());
		}else{
			$articles = FNews::model()->getArticleByCatAlias($alias,'','',$page->getLimit(),$page->getOffset());
		}
		$this->render('category', array(
								"Article"=>$articles,
								"Totals"	=>	$Totals,
								"page"	=>	$page,
								"itemOnPaging"	=>	$itemOnPaging,
								"curr_page"	=>	$curr_page,
								"alias"		=>	$alias
		));
	}
	public function actionError()
	{
		$this->render('error');
	}
	/**
	 * Creates a new comment.
	 * This method attempts to create a new comment based on the user input.
	 * If the comment is successfully created, the browser will be redirected
	 * to show the created comment.
	 * @param Post the post that the new comment belongs to
	 * @return Comment the comment instance
	 */
}